// var data_={
// 	time:"2017-07-02",
// 	data:{
// 			1:{
// 				dwplatf:"甘肃",
// 				data:{
// 					1:{产品名称:"基础包",产品价格:"30",产品销量:"130",总金额:"3900"},
// 					2:{产品名称:"基础包",产品价格:"30",产品销量:"50",总金额:"1500"},
// 					3:{产品名称:"",产品价格:"",产品销量:"",总金额:""},
// 				}
// 			}
// 			2:{
// 				dwplatf:"天津",
// 				data:{
// 					1:{产品名称:"基础包",产品价格:"30",产品销量:"130",总金额:"3900"},
// 					2:{产品名称:"基础包",产品价格:"30",产品销量:"50",总金额:"1500"},
// 					3:{产品名称:"天天童伴",产品价格:"30",产品销量:"50",总金额:"1500"},
// 					4:{产品名称:"",产品价格:"",产品销量:"",总金额:""},
// 				}
// 			}
// 		}
	
// 	}



var table_list={
	options:{
		data:"",
		data_head:"",
		// config
		// necessary
		el:"",
		// not necessary default:false
	},
	init:function(options){
		this.options.el=options.el;
		this.options.data=options.data;
		this.options.data_head=options.data_head;
		this.options.dom=document.createDocumentFragment();
		// function
		this.thead_init();
		this.body_init();
	},
	thead_init:function(){
		var data_head=this.options.data_head;
		var dom=document.createElement("tr");
		for(var i in data_head){
			doma=document.createElement("th");
			$(doma).text(data_head[i]);
			$(dom).append(doma);
			// console.log(i.length)
		}
		$(this.options.el).find("thead").append(dom);
	},
	body_init:function(){
		$(this.options.el).find("tbody").append(this.options.dom);
		var content=document.createDocumentFragment();
		var sum_head=[];
		var sum_last=[];
		var judge_word=/^[^x00-xff]+$/;
		var judge=/^[0-9]+$/;
		var state=[true,true];
		var sum_=[1,1];
		var sum_a=[0,0]
		function compile(data){
			for(var i in data){
				if(!judge.test(i)){
					if(judge_word.test(i)){
						sum_head.push(i);
						state[0]=true;
						sum_[0]=1;
						sum_a[0]++;
					}else{
						sum_last.push(i);
						state[1]=true;
						sum_[1]=1;
						sum_a[1]++;
					}
					arguments.callee(data[i])
				}else{
					var dom=document.createElement("tr");
					var dom_head=document.createElement("th");
					dom_head.className="dom_head";
					var dom_last=document.createElement("th");
					dom_last.className="dom_last";
					$(dom_head).html(sum_head[sum_head.length-1])
					state[0]?($(dom).append(dom_head)):(sum_[0]=sum_[0]+1);
					state[0]=false;
					// console.log(sum_)
					// $(dom_head).attr("rowspan",sum_[0]);
					// console.log($(content));
					// console.log($(content).children(dom_head).eq(0).children('th').eq(0).html());
					// console.log(dom_head)
					$(content).children(dom_head).find(".dom_head").eq(sum_a[0]-1).attr("rowspan",sum_[0]);
					for(var j in data[i]){
						var doma=document.createElement("th");
						var text_=data[i][j]?data[i][j]:"&nbsp;";
						$(doma).html(text_);
						// console.log(data[i][j]);
						$(dom).append(doma);
					}
					$(dom_last).html(sum_last[sum_last.length-1]);
					state[1]?($(dom).append(dom_last)):(sum_[1]=sum_[1]+1);
					state[1]=false;
					$(content).children(dom_head).find(".dom_last").eq(sum_a[1]-1).attr("rowspan",sum_[1]);
					// console.log(dom)
					content.appendChild(dom);
				}
			}
		}
		compile(this.options.data);
		$(this.options.el).find("tbody").append(content);
	},
	
}